import java.util.*;

/**
 * @author LKQ
 * @date 2022/4/1 11:00
 * @description
 */
public class Solution {
    public static void main(String[] args) {

    }
    public int maximalNetworkRank(int n, int[][] roads) {
        List<Integer>[] graph = new List[n];
        for (int i = 0; i < n; i++) {
            graph[i] = new ArrayList<>();
        }
        for (int[] road : roads) {
            graph[road[0]].add(road[1]);
            graph[road[1]].add(road[0]);
        }
        int ans = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                int temp = graph[i].size() + graph[j].size();
                if (temp < ans) {
                    continue;
                }
                if (graph[i].contains(j)) {
                    temp -= 1;
                }
                ans = Math.max(ans, temp);
            }
        }
        return ans;
    }
}
